<?php

namespace App\Utils\Notice;

use App\Model\NoticeAdmin;
use App\Constants\Model\Notice as NoticeConstants;
use Hyperf\DbConnection\Model\Model;

/**
 * 提现
 * Class AdminWithdrawAudit
 * @package App\Utils\NoticeController
 */
class AdminWithdrawAudit extends Notice
{
    public $messageTemplate = "您好，您有多个新的提现申请待您完成";

    public $routeName = 'WithdrawCheck?type=0';

    public function toDatabase()
    {
        $data = $this->format($this->data);
        $model = new NoticeAdmin();
        $model->fill($data)->save();
    }

    public function format(array $data)
    {
        $return = [
            'admin_user_id' => $this->receiverId,
            'type' => NoticeConstants::ADMIN_WITHDRAW_AUDIT,
            'content' => $this->messageTemplate,
            'extension' => [
                'path' => $this->routeName
            ]
        ];

        $searches = [];
        foreach ($data['replaces'] as $replace => $content) {
            $searches[] = '%' . $replace . '%';
        }
        $return['content'] = str_replace($searches, $data['replaces'], $this->messageTemplate);

        return $return;
    }
}
